#include "dpdk.h"

int dpdk_init(int argc, char * argv[], struct rte_mempool ** pool){
    if(rte_eal_init(argc, argv) < 0){
        rte_exit(EXIT_FAILURE, "---->  ");
    }

    *pool = rte_pktmbuf_pool_create("g_pool", NUM_MBUFS, 0,0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
    if(!*pool) {
        rte_exit(EXIT_FAILURE, "----> rte_pktmbuf_pool_create ");
    }

    uint16_t port_num = rte_eth_dev_count_avail();
    if(port_num == 0){
        rte_exit(EXIT_FAILURE, "----> port_num == 0 ");
    }
    struct rte_eth_dev_info dev_info;
    rte_eth_dev_info_get(0, &dev_info);
    const int rx_queue_num = 1;
    const int tx_queue_num = 1;
    struct rte_eth_conf port_conf = {.rxmode = {.max_lro_pkt_size = RTE_ETHER_MAX_LEN}};
    rte_eth_dev_configure(0, rx_queue_num, tx_queue_num, &port_conf);

    if(rte_eth_rx_queue_setup(0, 0, 1024, rte_eth_dev_socket_id(0), NULL, *pool) < 0){
        rte_exit(EXIT_FAILURE, "----> rte_eth_rx_queue_setup ");
    }
    struct rte_eth_txconf tx_conf = dev_info.default_txconf;
    tx_conf.offloads = port_conf.rxmode.offloads;
    if(rte_eth_tx_queue_setup(0,0,1024, rte_eth_dev_socket_id(0), &tx_conf) < 0){
        rte_exit(EXIT_FAILURE, "----> rte_eth_tx_queue_setup ");
    }
    if(rte_eth_dev_start(0) < 0){
        rte_exit(EXIT_FAILURE, "----> rte_eth_dev_setup ");
    }
    rte_eth_promiscuous_enable(0);
}

void dpdk_run(){}
void dpdk_close(){

    // rte_pdump_uninit();
    // flow_flush();
    // port_stop_all();
    // kni_stop();
    // rte_eal_cleanup();
}